<?php
    class User_m extends Model{
        function User_m(){
            parent::Model();
            $this->load->database();    
        }
        function get_all_user($per_page,$offset){
            $this->db->select('client.id,client.nom,client.email,client.prenom,client.tel');
            $this->db->from('client');
            $this->db->order_by('id','DESC');
            $this->db->limit($per_page,$offset);
            $query=$this->db->get();
            return $query->result_array();
        }
        function check_inscription($compte){
          $email=$compte['email'];
          $query = $this->db->get_where('client', array('email'=>$email));
          return $query;
          
      }
      function get_user($id){
    $query = $this->db->get_where('client', array('id'=>$id)); 
         return $query->row_array();  
      }
     function get_order_user($id)  {
             $this->db->select('commande.*, method_paiement.nom as methodnom');
            $this->db->from('commande');
            $this->db->join('method_paiement', 'commande.method = method_paiement.id');   
            $this->db->where(array('commande.idclient'=>$id));
            $query=$this->db->get();
         return $query->result_array();  
     }
      function delete_user($id){
          $query = $this->db->get_where('commande', array('idclient'=>$id)); 
                   
                    if ($query->num_rows()>0) 
                   { 
                       foreach($query->result_array() as $aRow):
                       $this->db->delete('detail_commande',array('idcommande'=>$aRow['id']));  
                            endforeach;
                   }
                 
           $this->db->delete('commande',array('idclient'=>$id));
          return $this->db->delete('client',array('id'=>$id));   
      }
      
       function update_user($data,$id) {
         return $this->db->update('client',$data,array('id'=>$id));     
       }
      function envoyer_inscription($data){
           $query= $this->db->insert('client',$data);
            return $query;
            }
    }
?>
